#include "dialog.h"
#include "ui_dialog.h"

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    connect(&threadShow, SIGNAL(newValue(int*,int,int)), this, SLOT(onThread_newValue(int*,int,int)));
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::onThread_newValue(int *data, int count, int seq){
    QString str = QString::asprintf("第 %d 个缓冲区", seq);
    for (int i = 0; i < count; i++){
        str += QString::asprintf("%d,  ", data);
        data++;
    }
    str += "\n";
    ui -> plainTextEdit ->appendPlainText(str);
}

void Dialog::on_threadStart_clicked()
{
    threadShow.start();
    threadDAQ.start();
    ui -> producer -> setText("DAQ START!!!");
    ui -> consumer -> setText("SHOW START!!!");
}

void Dialog::on_stopThread_clicked()
{
    threadShow.terminate();
    threadShow.wait();
    threadDAQ.terminate();
    threadDAQ.wait();
    ui -> producer -> setText("DAQ STOP!!!");
    ui -> consumer -> setText("SHOW STOP!!!");
}

void Dialog::on_clearText_clicked()
{
    ui -> plainTextEdit ->clear();
}
